/*Joseph A. Coll
RCV AP Controls Check
7/23/2025*/

*Load data
use "G:\My Drive\Backup 08202022\Working Papers\RCV and AP\Data and Methods\RCV AP Data Cleaned.dta", clear
cd "G:\My Drive\Backup 08202022\Working Papers\RCV and AP\Tables and Figures RCV AP"

********************************************************************************	
********************************************************************************
********************************************************************************
**#Main Analyses and Figures
********************************************************************************
********************************************************************************
********************************************************************************	

********************************************************************************
*Does Treatment Affect Affective Polarization
********************************************************************************
*FT
	*Affective polarization 
	reg ap_ft_change i.treatment age female educ white liberal conserv moderate dem_wlean rep_wlean
	estimates store ap_ft_change_con
	margins, at(treatment=(1(1)3)) post 
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Affective Polarization {&Delta} ") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.035 .035)) ///
	ylabel(-.03(.01).03) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_ft_change_con, replace) 
	graph export ap_ft_change_con.png, replace
	
	*In group
	reg ap_ft_ip_change  i.treatment age female educ white liberal conserv moderate dem_wlean rep_wlean
	estimates store ap_ft_ip_change_con
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("In-Group Affect {&Delta}") ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	yscale(r(-.035 .035)) ///
	ylabel(-.03(.01).03) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_ft_ip_change_con, replace) 
	graph export ap_ft_ip_change_con.png, replace	
	
	*Outgroup
	reg ap_ft_op_change  i.treatment age female educ white liberal conserv moderate dem_wlean rep_wlean 
	estimates store ap_ft_op_change_con
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Out-Group Affect {&Delta}") ///
	yscale(r(-.035 .035)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_ft_op_change_con, replace) 
	graph export ap_ft_op_change_con.png, replace	
	
	coefplot ap_ft_change_con ap_ft_ip_change_con ap_ft_op_change_con, ///
	drop(_cons) xline(0) ///
	xscale(r(-.015 .015)) ///
	xlabel(-.01(.01).01) ///
	scheme(plotplain) ///
	legend(order(2 "In- minus Out-Ideology" 4 "In-Ideology" 6 "Out-Ideology") row(1) pos(6)) ///
	title("Feeling Thermometer") ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
	cond(@pval<.001, string(@b,"%9.3f") + "***", ///
	cond(@pval<.01, string(@b,"%9.3f") + "**", ///
	cond(@pval<.05, string(@b,"%9.3f") + "*", ///
	string(@pval,"%9.3f")))))) ///
	mlabpos(12) ///
	mlabgap(2.5) ///
	name(coef_ft_con, replace)

	graph combine ap_ft_change_con ap_ft_ip_change_con ap_ft_op_change_con, ///
	ycommon xcommon ///
	rows(1) ///
	name(ft_combined_con, replace)
	graph export ft_combined_con.png, replace 

*Traits
	*Affective polarization
	reg ap_traits_change  i.treatment age female educ white liberal conserv moderate dem_wlean rep_wlean
	estimates store ap_traits_change_con
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Affective Polarization {&Delta} ") ///
	yscale(r(-.04 .04)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_traits_change_con, replace) 
	graph export ap_traits_change_con.png, replace
	
	*In group
	reg ap_traits_ip_change  i.treatment age female educ white liberal conserv moderate dem_wlean rep_wlean
	estimates store ap_traits_ip_change_con
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("In-Group Affect {&Delta} ") ///
	yscale(r(-.04 .04)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_traits_ip_change_con, replace) 
	graph export ap_traits_ip_change_con.png, replace
	
	*Out group
	reg ap_traits_op_change i.treatment age female educ white liberal conserv moderate dem_wlean rep_wlean
	estimates store ap_traits_op_change_con
	margins, at(treatment=(1(1)3)) post
	coefplot, vertical ///
	ciopts(recast(rcap) msize(small)) ///
	scheme(plotplain) ///
	xlabel(1 `" "Plurality" "Comp."' 2 `" "RCV" "Comp."'  3 `" "RCV" "Comp." "& Endorse"' ) ///
	xscale(r(1.25 2.25)) ///
	title("", size(medium)) ///
	ytitle("Out-Group Affect {&Delta} ") ///
	yscale(r(-.04 .04)) ///
	ylabel(-.03(.01).03) ///
	yline(0, lpattern(longdash) lcolor(black%60)) ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
		cond(@pval<.05, string(@b,"%9.3f") + "***", ///
		cond(@pval<.01, string(@b,"%9.3f") + "**", ///
		cond(@pval<.001, string(@b,"%9.3f") + "*", ///
		string(@pval,"%9.3fThe")))))) ///
	name(ap_traits_op_change_con, replace) 
	graph export ap_traits_op_change_con.png, replace
	
	coefplot ap_traits_change_con ap_traits_ip_change_con ap_traits_op_change_con, ///
	drop(_cons) xline(0) ///
	xscale(r(-.015 .015)) ///
	xlabel(-.01(.01).01) ///
	scheme(plotplain) ///
	legend(order(2 "In- minus Out-Ideology" 4 "In-Ideology" 6 "Out-Ideology") row(1) pos(6)) ///
	title("Traits") ///
	mlabel(cond(@pval>.05, string(@b,"%9.3f") + "", ///
	cond(@pval<.001, string(@b,"%9.3f") + "***", ///
	cond(@pval<.01, string(@b,"%9.3f") + "**", ///
	cond(@pval<.05, string(@b,"%9.3f") + "*", ///
	string(@pval,"%9.3f")))))) ///
	mlabpos(12) ///
	mlabgap(2.5) ///
	name(coef_t_con, replace)

	graph combine ap_traits_change_con ap_traits_ip_change_con ap_traits_op_change_con, ///
	ycommon xcommon ///
	rows(1) ///
	name(traits_combined_con, replace)
	graph export traits_combined_con.png, replace 
	
	
	graph combine ap_ft_change_con ap_ft_ip_change_con ap_ft_op_change_con ///
	 ap_traits_change_con ap_traits_ip_change_con ap_traits_op_change_con, ///
	ycommon xcommon ///
	rows(2) ///
	name(both_combined_con, replace)
	graph export both_combined_con.png, replace 

*Feeling Thermometer table
	esttab ap_ft_change_con ap_ft_ip_change_con ap_ft_op_change_con ///
	using apft_con.tex, replace ///
	cells(b(star fmt(3)) se(fmt(3) par) ) starlevels( * 0.05 ** 0.01 *** 0.001) ///
	label ///
	stat(r2 N, fmt(2 0) label("R$^2$" "\textit{N}")) ///
	nodepvars nobase noomitted interaction(" x ") ///
	drop() ///
	style(tex) compress ///
	title("Electoral System, Candidate Communication, and Change in Partisan Affect (Feeling Thermometer)\label{tab:apftcon}") ///
	mlabel("Affective Polarization" "In-Group" "Out-Group") 
		
*Traits table
	esttab ap_traits_change_con ap_traits_ip_change_con ap_traits_op_change_con ///
	using apt_con.tex, replace ///
	cells(b(star fmt(3)) se(fmt(3) par) ) starlevels( * 0.05 ** 0.01 *** 0.001) ///
	label ///
	stat(r2 N, fmt(2 0) label("R$^2$" "\textit{N}")) ///
	nodepvars nobase noomitted interaction(" x ") ///
	drop() ///
	style(tex) compress ///
	title("Electoral System, Candidate Communication, and Change in Partisan Affect (Traits)\label{tab:aptcon}") ///
	mlabel("Affective Polarization" "In-Group" "Out-Group") 	
	